package xyz.coolcsm.security.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import xyz.coolcsm.security.config.JsonResult;
import xyz.coolcsm.security.config.ResultTool;
import xyz.coolcsm.security.entity.Resource;
import xyz.coolcsm.security.entity.Say;
import xyz.coolcsm.security.service.RedisService;
import xyz.coolcsm.security.service.SayService;

import java.util.List;
/**
 * @author 什锦
 * @since 2021-06-1
 */

@RestController
public class SayController {

    @Autowired
    SayService sayService;

    @Autowired
    RedisService redisService;

    //公告分时间展示
    @GetMapping("/api/say/{time}")
    public JsonResult questionListPage(@PathVariable("time") String time){
        String key = "redis:say:" +time;
        Object object = redisService.get(key);
        if (object == null){
            List<Say> list = sayService.listByMonth(time.replace("-", ""));
            redisService.set(key,list);
            return ResultTool.success(list);
        }
        List<Resource>  resourcePage = (List<Resource> ) object;
        return ResultTool.success(resourcePage);
    }

}
